from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

def main():
    iris = load_iris()
    x = iris.data[:75, [0, 3]]
    y = iris.target[:75]
    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
    # print(y_train, y_test)
    model = LogisticRegression(max_iter=5000)    # 最大迭代次数 max_iter
    model.fit(x_train, y_train)
    train_score = model.score(x_train, y_train)
    test_score = model.score(x_test, y_test)
    print(f'train score: {train_score: .6f};\n test score: {test_score: .6f};'.format(
     train_score=train_score, test_score=test_score))


if __name__ == '__main__':
    main()
